/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */
package com.javacommunity.controller.bean;

import com.javacommunity.model.dao.CategoryDAO;
import com.javacommunity.model.dao.CommentDAO;
import com.javacommunity.model.dao.PostDAO;
import com.javacommunity.model.dao.PostVotationDAO;
import com.javacommunity.model.dao.impl.CategoryDAOImpl;
import com.javacommunity.model.dao.impl.CommentDAOImpl;
import com.javacommunity.model.dao.impl.PostDAOImpl;
import com.javacommunity.model.dao.impl.PostVotationDAOImpl;
import com.javacommunity.model.entity.Post;
import com.javacommunity.util.Support;
import java.util.ArrayList;
import java.util.List;
import javax.annotation.PostConstruct;
import javax.faces.bean.ManagedBean;
import javax.faces.bean.ManagedProperty;
import javax.faces.bean.RequestScoped;

/**
 *
 * @author Cong Pham Dinh
 */
@ManagedBean
@RequestScoped
public class PostCommentBean {

    private final PostDAO postDAO = PostDAOImpl.getInstance();
    private final CommentDAO commentDAO = CommentDAOImpl.getInstance();
    private final PostVotationDAO postVotationDAO = PostVotationDAOImpl.getInstance();
    private final CategoryDAO categoryDAO = CategoryDAOImpl.getInstance();

    private List<Post> posts = new ArrayList<Post>();

    private Post post = new Post();

    @ManagedProperty(value = "#{param.id}")
    private int postId;

    @PostConstruct
    public void init() {
        post = postDAO.getPostById(getPostId());
    }

    public String showPost() {
        return "show-post.jsf";
    }

    public int getVotes() {
        return postVotationDAO.countVotation(post);
    }

    /**
     * @return the posts
     */
    public List<Post> getPosts() {
        return posts;
    }

    /**
     * @param posts the posts to set
     */
    public void setPosts(List<Post> posts) {
        this.posts = posts;
    }

    /**
     * @return the post
     */
    public Post getPost() {
        return post;
    }

    /**
     * @param post the post to set
     */
    public void setPost(Post post) {
        this.post = post;
    }

    /**
     * @return the postId
     */
    public int getPostId() {
        return postId;
    }

    /**
     * @param postId the postId to set
     */
    public void setPostId(int postId) {
        this.postId = postId;
    }

}
